<template>
  <div>
    <el-form ref="form" :model="form" label-width="80px">
      <el-card class="box-card" style="margin-top: 20px;">
        <div slot="header" class="clearfix">
          <span>摘要</span>
        </div>
        <div>
          <el-form-item label="原文">
          <el-input type="textarea" v-model="form.src" :rows="10"></el-input>
        </el-form-item>
        <el-form-item label="密文">
          <el-input type="textarea" v-model="form.toEnc" :rows="10"></el-input>
        </el-form-item>
        </div>
      </el-card>
  </el-form>
</div>
</template>

<script>
import { sm3 } from '../../utils/crypto_digest'
export default {
  name: 'Sm3ToolLine',
  components: {},
  props: {},
  data () {
    return {
      form: {
        src: '',
        toEnc: ''
      }
    }
  },
  watch: {
    'form.src': {
      handler (newValue, oldVal) {
        this.enc()
      },
      deep: false // 深度监听
    }
  },
  computed: {},
  methods: {
    enc () {
      if (this.form.src) {
        let lines = this.form.src.split('\n')
        let encs = []
        for (let line of lines) {
          if (!line) {
            continue
          }
          encs.push(sm3(line, this.encKey))
        }
        this.form.toEnc = encs.join('\n')
      }
    }
  },
  created () {},
  mounted () {}
}
</script>
<style scoped>
</style>
